package com.Txunda.fxw.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.Txunda.fxw.R;
import com.Txunda.fxw.ui.adapter.model.MyViewHolder;
import com.bumptech.glide.Glide;

import java.util.List;
import java.util.Map;

public class MyRecyclerAdapter extends RecyclerView.Adapter<MyViewHolder> {


    private List<Map<String, String>> list;

    public Context mContext;

    public List<Map<String, String>> getList() {
        return list;
    }

    public void setList(List<Map<String, String>> list) {
        this.list = list;
    }


    public MyRecyclerAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getItemCount() {
        int ret = 0;
        if (list != null) {
            ret = list.size();
        }
        return ret;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {

        Glide.with(mContext).load(list.get(position).get("pic")).into(holder.getItem_img());
        //��Ŀ����¼�����
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String url = list.get(position).get("url");
                Uri uri = Uri.parse(url);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                mContext.startActivity(intent);
            }
        });
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup arg0, int arg1) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.main_item, arg0, false);
        return new MyViewHolder(view);
    }

}

